package com.crois.barrier.admin.controller;


import com.crois.barrier.admin.resp.BarrierResponseWrapper;
import com.crois.barrier.common.utils.UtilsAndCommons;
import com.crois.barrier.common.response.BarrierResponseEntity;
import com.zhimydou.cloud.auth.common.dto.AuthClientPageReqDto;
import com.zhimydou.cloud.auth.common.dto.ClientDto;
import com.zhimydou.cloud.auth.fegin.client.AuthClient;
import com.zhimydou.cloud.common.resp.ApiResponse;
import com.zhimydou.zdf.wf.domain.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 11:18 2021/10/28
 */
@RequestMapping(UtilsAndCommons.DEFAULT_BARRIER_ADMIN_CLIENT_CONTEXT)
@RestController
public class AuthClientCtl {

    @Autowired
    private AuthClient authClient;


    /***
     * barrier client page
     */
    @GetMapping(UtilsAndCommons.BARRIER_PAGE_CONTEXT)
    public BarrierResponseEntity<?> clientPage(AuthClientPageReqDto authClientPageReqDto){
        ApiResponse<Page<ClientDto>> clientPage = authClient.getClientPage(authClientPageReqDto.getClientName(),
                authClientPageReqDto.getCurrentPage(),
                authClientPageReqDto.getPageSize());
        return BarrierResponseWrapper.ok(clientPage.getData());
    }

    /***
     * barrier client page
     */
    @GetMapping(UtilsAndCommons.BARRIER_LIST_CONTEXT)
    public BarrierResponseEntity<?> clientList(@RequestParam(value = "clientName",required = false)  String clientName){
        ApiResponse<List<ClientDto>> clientClientList = authClient.getClientList(clientName);
        return BarrierResponseWrapper.ok(clientClientList.getData());
    }

    /***
     * barrier client detail
     */
    @GetMapping(UtilsAndCommons.BARRIER_DETAIL_CONTEXT+"/{clientId}")
    public BarrierResponseEntity<?> clientDetail(@PathVariable("clientId") Long clientId){
        ApiResponse clientDetail = authClient.getClientDetail(clientId);
        return BarrierResponseWrapper.ok(clientDetail.getData());
    }

    /***
     * barrier client delete
     */
    @DeleteMapping(UtilsAndCommons.BARRIER_DELETE_CONTEXT+"/{clientId}")
    public BarrierResponseEntity<?> clientDelete(@PathVariable("clientId") Long clientId){
        authClient.clientDelete(clientId);
        return BarrierResponseWrapper.ok();
    }

    /***
     * barrier client add
     */
    @PostMapping(UtilsAndCommons.BARRIER_ADD_CONTEXT)
    public BarrierResponseEntity<?> clientAdd(@RequestBody ClientDto clientDto){
        ApiResponse clientDetail = authClient.clientAdd(clientDto);
        return BarrierResponseWrapper.ok(clientDetail.getData());
    }

    /***
     * barrier client update
     */
    @PutMapping(UtilsAndCommons.BARRIER_UPDATE_CONTEXT+"/{clientId}")
    public BarrierResponseEntity<?> clientUpdate(@PathVariable("clientId") Long clientId,@RequestBody ClientDto clientDto){
        ApiResponse clientDetail = authClient.clientEdit(clientId,clientDto);
        return BarrierResponseWrapper.ok(clientDetail.getData());
    }

}
